package controller;

import java.util.Collection;
import model.Hardware;
import dao.HardwareDAO;

public class HardwareController {
	
	private HardwareDAO hardwareDAO;

	public boolean inserirHardware(String descricao) throws Exception {
		Hardware hardware = new Hardware(0, descricao);
		return getHardwareDAO().inserir(hardware);
	}

	public boolean alterarHardware(int id, String descricao) throws Exception {
		Hardware hardware = buscarHardwarePorId(id);
		hardware.setDescricao(descricao);
		return getHardwareDAO().alterar(hardware);
	}
	
	public boolean excluirHardware(int id) throws Exception {
		Hardware hardware = buscarHardwarePorId(id);
		return getHardwareDAO().delete(hardware);
	}
	
	public Hardware buscarHardwarePorId(int id) throws Exception {
		return getHardwareDAO().buscarHardwarePorId(id);
	}

	public Collection<Hardware> buscarTodos() throws Exception {
		return getHardwareDAO().buscarTodos();
	}
	
	public HardwareDAO getHardwareDAO() {
		if (hardwareDAO == null){
			hardwareDAO = new HardwareDAO();
		}
		return hardwareDAO;
	}
}